<?php
/**
 * Help page controller
 *
 * @author Dima
 *
 *
 */

class Admin_HelpController extends modules_admin_controllers_ControllerBase
{
	protected $_bForLoggedUsersOnly = false;
	
//----------------------------------------------------------------------------------------------------
	
	public function init()
	{
		if (! $this->getRequest()->isXmlHttpRequest())
		{
		
			parent::init();
			$this->view->title = 'Help';
		
			$this->view->menuHelp	= 
			'<a class="sexybutton sexysimple " href="/admin/help/add">' . 
				'&nbsp;&nbsp;&nbsp;Add New Page</a>';
		}
		
		$this->_helper->AjaxContext()->initContext('json');		
	}
	
//----------------------------------------------------------------------------------------------------

	public function indexAction()
	{
		$this->view->title = 'Help';
		$this->view->headScript()->appendFile('/js/resources.js');
		$this->view->headScript()->appendFile('/js/help.js');
		
		$oRequest 	= $this->getRequest();
		$page 		= $oRequest->getParam('page');
		
		$allHelp	= models_HelpMapper::getAll($page);
		
		$this->view->allHelp		= $allHelp['array'];
		$this->view->paginator 		= $allHelp['paginator'];			
	}
	
//----------------------------------------------------------------------------------------------------
	
	public function addAction()
	{
		$this->view->title 	= 'Add Help Page';
		$oRequest 			= $this->getRequest();
		
		if ($oRequest->isPost())
		{
			$title					= strip_tags($oRequest->getParam('title'));
			$content				= strip_tags($oRequest->getParam('content'));

			$aData['title']			= $title;
			$aData['content']		= $content;
			
			$idItem = models_HelpMapper::saveArray($aData, 'models_DbTable_Help');

			$this->_redirect('/admin/help');
		}
		else
		{
			$allHelp				= models_HelpMapper::getAll();
			$this->view->allHelp	= $allHelp['array'];;			
			$this->view->headScript()->appendFile('/js/addhelp.js');
		}
	}
	
//----------------------------------------------------------------------------------------------------
	
	public function editAction()
	{
		$this->view->title 	= 'Edit help Page';
		$oRequest 			= $this->getRequest();
		if ($oRequest->isPost())
		{
			$id						= strip_tags($oRequest->getParam('id'));
			$title					= strip_tags($oRequest->getParam('title'));
			$content				= strip_tags($oRequest->getParam('content'));

			$aData['title']			= $title;
			$aData['content']		= $content;
									
			$idItem 	= models_HelpMapper::update($id, $aData, 'models_DbTable_Help');
			$this->_redirect('/admin/help');
		}
		else
		{
			$id								= $oRequest->getParam('id');
			$oItem							= models_HelpMapper::findById($id);
			$allCardCategory				= models_HelpMapper::getAll();
			$this->view->allCardCategory	= $allCardCategory['array'];;			
			
			$this->view->oItem	= $oItem;
		}
	}
		
//----------------------------------------------------------------------------------------------------
//----------------------------------------------------------------------------------------------------
	
}